////////////////////////////////////////////////////////////////////////////// 
//
//  dwc_e12mp_phy_x4_ns_funcs.v
//
//  UP16 functions
//
//  Original Author: Ameer Youssef
//  Current Owner:   Ameer Youssef
//
////////////////////////////////////////////////////////////////////////////// 
//
// Copyright (C) 2012 Synopsys, Inc.  All rights reserved.
//
// SYNOPSYS CONFIDENTIAL - This is an unpublished, proprietary work of
// Synopsys, Inc., and is fully protected under copyright and trade secret
// laws.  You may not view, use, disclose, copy, or distribute this file or
// any information contained herein except pursuant to a valid written
// license agreement. It may not be used, reproduced, or disclosed to others
// except in accordance with the terms and conditions of that agreement.
//
////////////////////////////////////////////////////////////////////////////// 
//
//    Perforce Information
//    $Author: ameer $
//    $File: //dwh/up16/main/dev/pma/include/dwc_e12mp_phy_x4_ns_funcs.v $
//    $DateTime: 2014/08/21 15:33:22 $
//    $Revision: #2 $
//
////////////////////////////////////////////////////////////////////////////// 


// --------------------------------------------------------------------
// bin2therm_1 - Converts a binary word with a max value of 4'd1 into
//               a 1-bit thermometer code 
// --------------------------------------------------------------------
function bin2therm_1;
  input [3:0] w;
  begin 
    bin2therm_1 = w[3] || w[2] || w[1] || w[0];
  end

endfunction // bin2therm_1

// --------------------------------------------------------------------
// bin2therm_2 - Converts a binary word with a max value of 4'd2 into
//               a 2-bit thermometer code 
// --------------------------------------------------------------------
function [1:0] bin2therm_2;
  input [3:0] w;
  begin 
    bin2therm_2[0] = bin2therm_1(w[3:0]);
    bin2therm_2[1] = w[3] || w[2] || w[1];
  end

endfunction // bin2therm_2

// --------------------------------------------------------------------
// bin2therm_3 - Converts a binary word with a max value of 4'd3 into
//               a 3-bit thermometer code 
// --------------------------------------------------------------------
function [2:0] bin2therm_3;
  input [3:0] w;
  begin 
    bin2therm_3[1:0] = bin2therm_2(w[3:0]);
    bin2therm_3[2]   = w[3] || w[2] || (w[1] && w[0]);
  end

endfunction // bin2therm_3

// --------------------------------------------------------------------
// bin2therm_4 - Converts a binary word with a max value of 4'd4 into
//               a 4-bit thermometer code 
// --------------------------------------------------------------------
function [3:0] bin2therm_4;
  input [3:0] w;
  begin 
    bin2therm_4[2:0] = bin2therm_3(w[3:0]);
    bin2therm_4[3]   = w[3] || w[2];
  end
endfunction // bin2therm_4

// --------------------------------------------------------------------
// bin2therm_5 - Converts a binary word with a max value of 4'd5 into
//               a 5-bit thermometer code 
// --------------------------------------------------------------------
function [4:0] bin2therm_5;
  input [3:0] w;
  begin 
    bin2therm_5[3:0] = bin2therm_4(w[3:0]);
    bin2therm_5[4]   = w[3] || (w[2] && (w[1] || w[0]));
  end
endfunction // bin2therm_5

// --------------------------------------------------------------------
// bin2therm_6 - Converts a binary word with a max value of 4'd6 into
//               a 6-bit thermometer code 
// --------------------------------------------------------------------
function [5:0] bin2therm_6;
  input [3:0] w;
  begin 
    bin2therm_6[4:0] = bin2therm_5(w[3:0]);
    bin2therm_6[5]   = w[3] || (w[2] && w[1]);
  end
endfunction // bin2therm_6

// --------------------------------------------------------------------
// bin2therm_7 - Converts a binary word with a max value of 4'd7 into
//               a 7-bit thermometer code 
// --------------------------------------------------------------------
function [6:0] bin2therm_7;
  input [3:0] w;
  begin 
    bin2therm_7[5:0] = bin2therm_6(w[3:0]);
    bin2therm_7[6]   = w[3] || (w[2] && w[1] && w[0]);
  end
endfunction // bin2therm_9

// --------------------------------------------------------------------
// bin2therm_8 - Converts a binary word with a max value of 4'd8 into
//               a 8-bit thermometer code 
// --------------------------------------------------------------------
function [7:0] bin2therm_8;
  input [3:0] w;
  begin 
    bin2therm_8[6:0] = bin2therm_7(w[3:0]);
    bin2therm_8[7]   = w[3];
  end
endfunction // bin2therm_8

// --------------------------------------------------------------------
// bin2therm_9 - Converts a binary word with a max value of 4'd9 into
//               a 9-bit thermometer code 
// --------------------------------------------------------------------
function [8:0] bin2therm_9;
  input [3:0] w;
  begin 
    bin2therm_9[7:0] = bin2therm_8(w[3:0]);
    bin2therm_9[8]   = w[3] && (w[2] || w[1] || w[0]);
  end
endfunction // bin2therm_9

// --------------------------------------------------------------------
// bin2therm_10 - Converts a binary word with a max value of 4'd10 into
//                a 10-bit thermometer code 
// --------------------------------------------------------------------
function [9:0] bin2therm_10;
  input [3:0] w;
  begin 
    bin2therm_10[8:0] = bin2therm_9(w[3:0]);
    bin2therm_10[9]   = w[3] && (w[2] || w[1]);
  end
endfunction // bin2therm_10

// --------------------------------------------------------------------
// bin2therm_11 - Converts a binary word with a max value of 4'd11 into
//                a 11-bit thermometer code 
// --------------------------------------------------------------------
function [10:0] bin2therm_11;
  input [3:0] w;
  begin 
    bin2therm_11[9:0] = bin2therm_10(w[3:0]);
    bin2therm_11[10]  = w[3] && (w[2] || (w[1] && w[0]));
  end
endfunction // bin2therm_11

// --------------------------------------------------------------------
// bin2therm_12 - Converts a binary word with a max value of 4'd12 into
//                a 12-bit thermometer code 
// --------------------------------------------------------------------
function [11:0] bin2therm_12;
  input [3:0] w;
  begin 
    bin2therm_12[10:0] = bin2therm_11(w[3:0]);
    bin2therm_12[11]   = w[3] && w[2];
  end
endfunction // bin2therm_12

// --------------------------------------------------------------------
// bin2therm_13 - Converts a binary word with a max value of 4'd13 into
//                a 13-bit thermometer code 
// --------------------------------------------------------------------
function [12:0] bin2therm_13;
  input [3:0] w;
  begin 
    bin2therm_13[11:0] = bin2therm_12(w[3:0]);
    bin2therm_13[12]   = w[3] && w[2] && (w[1] || w[0]);
  end
endfunction // bin2therm_13

// --------------------------------------------------------------------
// bin2therm_14 - Converts a binary word with a max value of 4'd14 into
//                a 14-bit thermometer code 
// --------------------------------------------------------------------
function [13:0] bin2therm_14;
  input [3:0] w;
  begin 
    bin2therm_14[12:0] = bin2therm_13(w[3:0]);
    bin2therm_14[13]   = w[3] && w[2] && w[1];
  end
endfunction // bin2therm_14

// --------------------------------------------------------------------
// bin2therm_15 - Converts a binary word with a max value of 4'd15 into
//                a 15-bit thermometer code 
// --------------------------------------------------------------------
function [14:0] bin2therm_15;
  input [3:0] w;
  begin 
    bin2therm_15[13:0] = bin2therm_14(w[3:0]);
    bin2therm_15[14]   = w[3] && w[2] && w[1] && w[0];
  end
endfunction // bin2therm_15

// --------------------------------------------------------------------
// bin2therm_31 - Converts a binary word with a max value of 5'd31 into
//                a 31-bit thermometer code 
// --------------------------------------------------------------------
function [30:0] bin2therm_31;
  input [4:0] w;
  begin 
    bin2therm_31[14:0]  = {15{w[4]}} | bin2therm_15(w[3:0]);
    bin2therm_31[15]    = w[4];
    bin2therm_31[30:16] = {15{w[4]}} & bin2therm_15(w[3:0]);
  end
endfunction // bin2therm_15

// --------------------------------------------------------------------
// bin2onehot_30 - Converts a binary word with a max value of 5'd30 into
//                 a 30-bit onehot code 
// --------------------------------------------------------------------
function [29:0] bin2onehot_30;
  input [4:0] w;
  begin 
    bin2onehot_30[0]  = (w == 5'd1);
    bin2onehot_30[1]  = (w == 5'd2);
    bin2onehot_30[2]  = (w == 5'd3);
    bin2onehot_30[3]  = (w == 5'd4);
    bin2onehot_30[4]  = (w == 5'd5);
    bin2onehot_30[5]  = (w == 5'd6);
    bin2onehot_30[6]  = (w == 5'd7);
    bin2onehot_30[7]  = (w == 5'd8);
    bin2onehot_30[8]  = (w == 5'd9);
    bin2onehot_30[9]  = (w == 5'd10);
    bin2onehot_30[10] = (w == 5'd11);
    bin2onehot_30[11] = (w == 5'd12);
    bin2onehot_30[12] = (w == 5'd13);
    bin2onehot_30[13] = (w == 5'd14);
    bin2onehot_30[14] = (w == 5'd15);
    bin2onehot_30[15] = (w == 5'd16);
    bin2onehot_30[16] = (w == 5'd17);
    bin2onehot_30[17] = (w == 5'd18);
    bin2onehot_30[18] = (w == 5'd19);
    bin2onehot_30[19] = (w == 5'd20);
    bin2onehot_30[20] = (w == 5'd21);
    bin2onehot_30[21] = (w == 5'd22);
    bin2onehot_30[22] = (w == 5'd23);
    bin2onehot_30[23] = (w == 5'd24);
    bin2onehot_30[24] = (w == 5'd25);
    bin2onehot_30[25] = (w == 5'd26);
    bin2onehot_30[26] = (w == 5'd27);
    bin2onehot_30[27] = (w == 5'd28);
    bin2onehot_30[28] = (w == 5'd29);
    bin2onehot_30[29] = (w == 5'd30);
  end
endfunction // bin2onehot_30

